package hesso.smartdraw.ch.guielements;

import hesso.smartdraw.ch.DrawWallScreen;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.input.touch.TouchEvent;

public class WallMoveDot extends Rectangle {

	private WallLine endOf, startOf;
	private DrawWallScreen dws;
	
	public WallMoveDot(WallLine endOf, WallLine startOf, DrawWallScreen dws) {
		super(endOf.getX2() - 25, endOf.getY2() - 25, 50, 50);
		this.endOf = endOf;
		this.startOf = startOf;
		this.dws = dws;
	}

	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY){
		switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			break;
		case TouchEvent.ACTION_MOVE:
			this.setPosition(pSceneTouchEvent.getX() - 25, pSceneTouchEvent.getY() - 25);
			endOf.setPosition(endOf.getX1(), endOf.getY1(), pSceneTouchEvent.getX(), pSceneTouchEvent.getY());	
			startOf.setPosition( pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), startOf.getX2(), startOf.getY2());		
			break;
		case TouchEvent.ACTION_UP:
			this.dws.updateRoom(endOf.getModelWall());				
			break;
		}
		return true;
	}
}
